package com.firewolf.oa.utils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import com.firewolf.oa.entities.Department;

public class DepartmentUtil {
	
	/**
	 * 获取所有部门的树形结构
	 * @param topDepts
	 * @return
	 */
	public static List<Department> getAllDepartmentTree(String prefix,Collection<Department> topDepts){
		List<Department> deptList = new ArrayList<>();
		for(Department d : topDepts){
			Department d1 = new Department();
			d1.setId(d.getId());
			d1.setName(prefix+d.getName());
			deptList.add(d1);
			Set<Department> children = d.getChildren();
			List<Department> list2 = getAllDepartmentTree("　"+prefix, children);
			deptList.addAll(list2);
		}
		return deptList;
	}
	
}
